"""
# -*- coding:utf-8 -*-
@Project : data-science-master
@File : RandomForestRegression.py
@Author : Arsen
@Time : 2023/3/1 11:26

"""
# 构建随机森林回归模型

from sklearn import tree
from sklearn.datasets import load_boston
from sklearn.ensemble import RandomForestRegressor

# 加载数据
boston_house = load_boston()
boston_feature_name = boston_house.feature_names
boston_features = boston_house.data
boston_target = boston_house.target

# 构建模型
# help(RandomForestRegressor)
rgs = RandomForestRegressor(n_estimators=15)    # 随机森林模型
rgs = rgs.fit(boston_features, boston_target)
predict_1 = rgs.predict(boston_features)

# 对比模型
rgs2 = tree.DecisionTreeRegressor()             # 决策树模型，比较两个模型的预测结果
rgs2.fit(boston_features, boston_target)
predict_2 = rgs2.predict(boston_features)

print("随机森林 结果:\n" + str(predict_1))
print("==="*25)
print("决策树 结果:\n" + str(predict_1))
